<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>将字符串从 UTF-8 转换为 ISO-8859-1，替换无效或者无法表示的字符。</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.ucwords.html">« ucwords</a></li>
      <li style="float: right;"><a href="function.utf8-encode.html">utf8_encode »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.strings.html">字符串 函数</a></li>
    <li>将字符串从 UTF-8 转换为 ISO-8859-1，替换无效或者无法表示的字符。</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.utf8-decode" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">utf8_decode</h1> 
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">utf8_decode</span> &mdash; <span class="dc-title">
   将字符串从 UTF-8 转换为 ISO-8859-1，替换无效或者无法表示的字符。
  </span></p>

 </div>

 <div id="function.utf8-decode-refsynopsisdiv">
  <div class="warning"><strong class="warning">警告</strong><p class="simpara">此函数自 PHP 8.2.0
起<em class="emphasis">弃用</em>。强烈建议不要应用此函数。</p></div>
 </div>
 
 <div class="refsect1 description" id="refsect1-function.utf8-decode-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>utf8_decode</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>): <span class="type">string</span></div>

  <p class="para rdfs-comment">
   该函数将字符串 <code class="parameter">string</code> 从 <code class="literal">UTF-8</code> 编码转换为
   <code class="literal">ISO-8859-1</code>。字符串中不是有效 UTF-8 字节或者不存在于 <code class="literal">ISO-8859-1</code>
   的 <code class="literal">UTF-8</code> 字符（即 <code class="literal">U+00FF</code> 以上的码点）将转化为 <code class="literal">?</code>。
  </p>

  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    Many web pages marked as using the <code class="literal">ISO-8859-1</code> character
    encoding actually use the similar <code class="literal">Windows-1252</code> encoding,
    and web browsers will interpret <code class="literal">ISO-8859-1</code> web pages as
    <code class="literal">Windows-1252</code>. <code class="literal">Windows-1252</code> features
    additional printable characters, such as the Euro sign
    (<code class="literal">€</code>) and curly quotes (<code class="literal">“</code>
    <code class="literal">”</code>), instead of certain <code class="literal">ISO-8859-1</code>
    control characters. This function will not convert such
    <code class="literal">Windows-1252</code> characters correctly. Use a different
    function if <code class="literal">Windows-1252</code> conversion is required.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.utf8-decode-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">string</code></dt>

     <dd>

      <p class="para">
       UTF-8 编码的字符串。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.utf8-decode-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回 <code class="parameter">string</code> 的 ISO-8859-1 翻译。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.utf8-decode-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.2.0</td>
       <td>
        弃用此函数。
       </td>
      </tr>

      <tr>
       <td>7.2.0</td>
       <td>
        This function has been moved from the XML extension to the core of PHP.
        In previous versions, it was only available if the XML extension was installed.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.utf8-decode-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-4885">
   <p><strong>示例 #1 基础示例</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Convert&nbsp;the&nbsp;string&nbsp;'Zoë'&nbsp;from&nbsp;UTF-8&nbsp;to&nbsp;ISO&nbsp;8859-1<br /></span><span style="color: #0000BB">$utf8_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"\x5A\x6F\xC3\xAB"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$iso8859_1_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">utf8_decode</span><span style="color: #007700">(</span><span style="color: #0000BB">$utf8_string</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">bin2hex</span><span style="color: #007700">(</span><span style="color: #0000BB">$iso8859_1_string</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Invalid&nbsp;UTF-8&nbsp;sequences&nbsp;are&nbsp;replaced&nbsp;with&nbsp;'?'<br /></span><span style="color: #0000BB">$invalid_utf8_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"\xC3"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$iso8859_1_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">utf8_decode</span><span style="color: #007700">(</span><span style="color: #0000BB">$invalid_utf8_string</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$iso8859_1_string</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Characters&nbsp;which&nbsp;don't&nbsp;exist&nbsp;in&nbsp;ISO&nbsp;8859-1,&nbsp;such&nbsp;as<br />//&nbsp;'€'&nbsp;(Euro&nbsp;Sign)&nbsp;are&nbsp;also&nbsp;replaced&nbsp;with&nbsp;'?'<br /></span><span style="color: #0000BB">$utf8_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"\xE2\x82\xAC"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$iso8859_1_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">utf8_decode</span><span style="color: #007700">(</span><span style="color: #0000BB">$utf8_string</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$iso8859_1_string</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
5a6feb
string(1) &quot;?&quot;
string(1) &quot;?&quot;
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.utf8-decode-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.utf8-encode.html" class="function" rel="rdfs-seeAlso">utf8_encode()</a> - 将字符串从 ISO-8859-1 转换为 UTF-8 编码</span></li>
    <li class="member"><span class="function"><a href="function.mb-convert-encoding.html" class="function" rel="rdfs-seeAlso">mb_convert_encoding()</a> - 转换字符的编码</span></li>
    <li class="member"><span class="methodname"><a href="uconverter.transcode.html" class="methodname" rel="rdfs-seeAlso">UConverter::transcode()</a> - Convert a string from one character encoding to another</span></li>
    <li class="member"><span class="function"><a href="function.iconv.html" class="function" rel="rdfs-seeAlso">iconv()</a> - 字符串按要求的字符编码来转换</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>